package com.jersey.service;

import com.alibaba.fastjson.JSON;
import com.jersey.entity.User;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

/**
 * package com.jersey.service
 * description:
 *
 * @author tree
 * @date 2019-06-03 20:02
 */
@Path("/messages")
public class JerseyService {
    @GET
    @Path("hello-world")
    public String getMsg(){
        return "hello world!! - Jersey";
    }

    @GET
    @Path("/users")
    @Produces(MediaType.APPLICATION_JSON)
    public String  users(){
        List<User> list = new ArrayList<>();
        for(int i = 0 ;i < 3; i++) {
            list.add(new User(1, "user"+i, "user"+i+"@email.com"));
        }
        return JSON.toJSONString(list);
    }

    @GET
    @Path("/users2")
    @Produces(MediaType.APPLICATION_JSON)
    public Response users2(){
        List<User> list = new ArrayList<>();
        for(int i = 0 ;i < 5; i++) {
            list.add(new User(1, "user"+i, "user"+i+"@email.com"));
        }
        return Response.ok(list).build();
    }
    @GET
    @Path("/users3")
    @Produces(MediaType.APPLICATION_JSON)
    public List<User>  users3(){
        List<User> list = new ArrayList<>();
        for(int i = 0 ;i < 4; i++) {
            list.add(new User(1, "user"+i, "user"+i+"@email.com"));
        }
        return list;
    }
}
